@echo off

REM Zookeeper 地址和端口
set ZOOKEEPER_HOST=localhost
set ZOOKEEPER_PORT=2181
set ZOOKEEPER_HOME=D:\service\apache-zookeeper-3.8.4

REM 要设置的节点路径
set NODE_PATH=/my_node/config/db/smc

REM 设置 NODE_VALUE，逐行定义配置，使用特殊字符避免命令的解析错误
set NODE_VALUE1=druid.driverClassName=oracle.jdbc.OracleDriver
set NODE_VALUE2=druid.username=settle
set NODE_VALUE3=druid.password=settle
set NODE_VALUE4=druid.url=jdbc:oracle:thin:@//10.180.45.175:1521/settledb
set NODE_VALUE5=druid.initialSize=1
set NODE_VALUE6=druid.maxActive=100
set NODE_VALUE7=druid.minIdle=10
set NODE_VALUE8=druid.maxWait=60000
set NODE_VALUE9=druid.removeAbandoned=true
set NODE_VALUE10=druid.removeAbandonedTimeout=180
set NODE_VALUE11=druid.timeBetweenEvictionRunsMillis=60000
set NODE_VALUE12=druid.minEvictableIdleTimeMillis=25200000
set NODE_VALUE13=druid.validationQuery=SELECT 1 FROM DUAL
set NODE_VALUE14=druid.testWhileIdle=true
set NODE_VALUE15=druid.testOnBorrow=false
set NODE_VALUE16=druid.testOnReturn=false
set NODE_VALUE17=druid.connectionProperties=config.decrypt=false

REM 拼接最终的 NODE_VALUE
set NODE_VALUE=
for %%i in (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17) do (
    set NODE_VALUE=!NODE_VALUE! !NODE_VALUE%%i!
)

REM 检查 ZOOKEEPER_HOME 是否设置
if "%ZOOKEEPER_HOME%"=="" (
    echo 错误: ZOOKEEPER_HOME 未设置，请设置 ZOOKEEPER_HOME 环境变量。
    exit /b 1
)

REM 启用延迟环境变量扩展
setlocal enabledelayedexpansion

REM 使用 zkCli.sh 设置节点值
(
    echo create %NODE_PATH% "%NODE_VALUE%" -e
    echo exit
) | "%ZOOKEEPER_HOME%\bin\zkCli.cmd" -server %ZOOKEEPER_HOST%:%ZOOKEEPER_PORT%

echo 节点 %NODE_PATH% 的值已设置为 "%NODE_VALUE%"

endlocal